﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_Public;
using QLTV_BLL;

namespace QLTV_GiaoDien
{
    public partial class uc_ViTri : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_ViTri()
        {
            InitializeComponent();
        }
        public void Get_Load(int kt)
        {
            txt_Load.Text = kt.ToString();
        }
        ViTri_BLL vt_bll = new ViTri_BLL();
        private void uc_ViTri_Load(object sender, EventArgs e)
        {
            gridControl1.DataSource = vt_bll.LayDuLieu();
            txt_Load.Hide();
            
        }
        private void bbi_Them_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_ViTri f = new frm_ViTri();
            f.Flag = 0;
            f.MyGetData = new frm_ViTri.GetInt(Get_Load);
            f.ShowDialog();
        }

        private void bbi_Sua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_ViTri f = new frm_ViTri();
            f.Flag = 1;
            f.MyGetData = new frm_ViTri.GetInt(Get_Load);
            f.MaViTri = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Vị Trí").ToString());
            f.TenViTri = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Vị Trí").ToString();
            f.MoTa = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mô Tả").ToString();
            f.ShowDialog();
        }
        private void bbi_Xem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_ViTri f = new frm_ViTri();
            f.Flag = 2;
            f.MyGetData = new frm_ViTri.GetInt(Get_Load);
            f.MaViTri = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Vị Trí").ToString());
            f.TenViTri = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Vị Trí").ToString();
            f.MoTa = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mô Tả").ToString();
            f.ShowDialog();
        }
        private void txt_Load_TextChanged(object sender, EventArgs e)
        {
            if (txt_Load.Text == "1")
            {
                uc_ViTri_Load(sender, e);
                txt_Load.Text = "0";
            }
        }
        NhatKy_BLL nhatKy_bll = new NhatKy_BLL();
        NhatKy_Public nk = new NhatKy_Public();
        TrungGian tg = new TrungGian();
        private void bbi_Xoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ViTriLuuTru_Public vt = new ViTriLuuTru_Public();
            vt.MaViTri = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Vị Trí").ToString());
            vt.TenViTri = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Vị Trí").ToString();
            if (XtraMessageBox.Show("Bạn có muốn xóa Vị trí: '" + vt.TenViTri + "' có mã là: '" + vt.MaViTri + "' này không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                vt_bll.delete_viTri(vt);
                //
                string d = DateTime.Now.ToString();
                nk.MaNV = tg.MaNV;
                nk.NgayGio = d;
                nk.HanhDong = "Xóa";
                nk.MoTa = "Xóa thông tin Vị trí lưu trữ: '" + vt.TenViTri+ "'";
                nhatKy_bll.insert_nhatKy(nk, nk, nk, nk);
                //
                uc_ViTri_Load(sender,e);
            }
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            frm_ViTri f = new frm_ViTri();
            f.Flag = 2;
            f.MyGetData = new frm_ViTri.GetInt(Get_Load);
            f.MaViTri = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Vị Trí").ToString());
            f.TenViTri = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Vị Trí").ToString();
            f.MoTa = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mô Tả").ToString();
            f.ShowDialog();
        }

        private void bbi_In_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            
        }




    }
}
